// pages/recommendedPrizes.js
import util from '../../utils/util.js';
import $ from '../../utils/ajax.js';
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        shopList: {
            messageType: 0,
            memberType: 2,
            status: 0,
            page: 1,
            size: 10,
        },
        content:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        
    },
    onShow: function () {
        this.putIn()
    },
  
    putIn() {
        $.p(app.wxApp.url + 'messagereceive/getReceiveListByCondition', {...this.data.shopList}, app.onStrart, (res) => {
            let data = this.data.content;
            if (res.data.page === 1) {
                data = res.data.list
            } else {
                res.data.list.map((item) => {
                    data.push({
                        ...item
                    })
                })
            }
            this.setData({
                content: data
            })
            app.onShop()

        }, (res) => {
            util.showToast(res.data)
        })
    },
    //下拉刷新
    onPullDownRefresh() {

        this.setData({
            ['shopList.page']: 1,

        }, () => {
            this.putIn()
        })
        wx.stopPullDownRefresh()
    },
    //上拉加载
    onReachBottom() {
        this.data.shopList.page++ ,
        this.putIn()
    },
    goMessageDetails(e) {
        const type = e.currentTarget.dataset.type;
        const typeData = JSON.stringify(type);
        wx.setStorage({
            key: "messageData",
            data: typeData
        })

        wx.navigateTo({
            url: '/pages/recommendedPrizes/messageDetails/messageDetails'
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
   

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})